<template><i class="iconfont icon-dianzan1" @click="liked"></i></template>

<script>
import { likeAPI, onlikeAPI } from "@/api/user.js";

export default {
  props: {
    value: {
      tpye: [Number],
      require: true,
    },
    artid: {
      type: [Number, String, Object],
      require: true,
    },
  },
  methods: {
    async liked() {
      if (this.value < 1) {
        try {
          await likeAPI(this.artid);
          this.$toast("点赞成功");
          this.$emit("input", 1);
        } catch (err) {
          this.$toast("失败，请重试");
        }
      } else {
        try {
          await onlikeAPI(this.artid);
          this.$toast("取消点赞");
          this.$emit("input", -1);
        } catch (err) {
          this.$toast("失败，请重试");
        }
      }
    },
  },
};
</script>

<style>
</style>